<?php
/**
 * LOTUS client
 */
namespace app\api\utils;

class  Lotus{

    protected static $id=0;

    /**
     * 金额变动加入记录
     */
    public static function to_request($Method,$params){
        $url = "http://127.0.0.1:1234/rpc/v0";
        $token = config('token');
        $req_param = array(
            'jsonrpc'=>'2.0',
            'method'=>$Method,
            'id'=>self::$id++,
            'params'=>$params,
        );
        $opts = array(
            CURLOPT_TIMEOUT => 30,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
        );
        /* 根据请求类型设置特定参数 */
        $req_param = json_encode($req_param);
        $opts[CURLOPT_URL] = $url;
        // $opts[CURLOPT_URL] = $url;
        $opts[CURLOPT_POST] = 1;
        $opts[CURLOPT_POSTFIELDS] = $req_param;
        $opts[CURLOPT_HTTPHEADER] = array('Content-Type: application/json',"Authorization: Bearer {$token}");
        /* 初始化并执行curl请求 */
        $ch = curl_init();
        curl_setopt_array($ch, $opts);
        $data = curl_exec($ch);
        $error = curl_error($ch);
        curl_close($ch);
        return json_decode($data,1);
        if ($error) {//发生错误
            return ['success'=>false,'message'=>$error];
        } else {
            return ['success'=>true,'message'=>json_decode($data,1)];
        }
    }

}